package com.poetize.plus.entity.vo.page;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.poetize.plus.entity.po.Notice;
import io.swagger.v3.oas.annotations.media.Schema;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

/**
 * @Author zuosy
 * @Date 2024/3/30 14:43
 **/
public record NoticePageVO(
        @Schema(description = "id")
        Long id,
        @Schema(description = "公告标题")
        String title,
        @Schema(description = "是否启用")
        Boolean status,
        @Schema(description = "创建人")
        String createBy,
        @Schema(description = "创建时间")
        @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
        LocalDateTime createTime,
        @Schema(description = "修改时间")
        @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
        LocalDateTime updateTime
) {

    /**
     * 集合数据转分页
     * @param noticeList
     * @return
     */
    public static List<NoticePageVO> convertPageList(List<Notice> noticeList) {
        List<NoticePageVO> result = new ArrayList<>();
        noticeList.forEach(notice -> {
            NoticePageVO vo = new NoticePageVO(
                    notice.getId(),
                    notice.getTitle(),
                    notice.getStatus(),
                    notice.getCreateBy(),
                    notice.getCreateTime(),
                    notice.getUpdateTime());
            result.add(vo);
        });
        return result;
    }
}
